// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require("base");
    var leftMenu = require("../leftMenu/leftMenu");
    var topMenu = require("../topMenu/topMenu");
    var router = require("../hash/pageRouter");
    var dialog = require("dialog");
    var validate = require("validate");
    var databind = require("databind");
    var financingDetailInfo = require("./financingDetailInfo.js");
    var pageIndex = 1,
        pageSize = 10,
        totalPageCount = 1,
        totalRecordCount = 0; //分页初始化
    var imgSrc;
    var financeId ;
    var init = function(page){
    	financeId = page.params.financeId || base.getUrlParam("financeId");
    	
    	$(".table-section").removeClass("none");
    	$(".footer").removeClass("none");
    	$("#leftMenu1").find(".leftMenu-item").removeClass("leftMenu-active");
    	$("#leftMenu1 #newTaskList").parent(".leftMenu-item").addClass("leftMenu-active");
    	$("#leftMenu1 .leftMenu li:first-child").addClass("leftMenu-open");
    	inquireRecieveNoticePageList();
		financingDetailInfo.init(page);
		initEvent();
		
		router.init();
		
    };
	var initEvent = function(){
		//若未登录，则返回登陆页面
		if(base.getData("sid")==null||base.getData("sid")==""||base.getData("sid")==undefined){
			top.location.href="../login/login.html";
		}
		$(".page-content-main").on("click",".handle-type",function(){
				var recieveNoticeId = [];
           var $this = $(this).parents("tr.tr_style");
		   recieveNoticeId.push($this.attr("recieveNoticeId"));
		   	router.route("financing/cargoRecord.html?recieveNoticeId="+recieveNoticeId+"&financeId="+financeId,true);
			});
		
    };
    
    //查询收货通知列表
    var inquireRecieveNoticePageList = function(){
    	//var body = base.parseForm($(".page-content-search"));
    	base.fnAjax({
            action: "inquireRecieveNoticePageList.json",
            oData: {
            	pageIndex: pageIndex,
                pageSize: pageSize,
                financeId:financeId
            }, //传递参数
            fnSuccess: function(data) {
                if (data.status == 200) {
                	var tpl = $("#logisticsCompanyListTpl").html();
                    var html = juicer(tpl, data);
                    $("#newTaskListBody").html(html);
                    totalPageCount = data.totalPageCount;
                    totalRecordCount = data.totalRecordCount;
                    base.pageControl(
                    	$("#pagenation"),
                        totalRecordCount,
                        data.pageIndex,
                        data.pageSize,
                        function(p) {
                            pageIndex = p;
                            inquireRecieveNoticePageList();
                    });
                } else {
                    base.alert(2,"信息获取失败");
                }
            }
        });
    }
    return {
        init:init
    };
});